package org.odefu.model.project;

public final class TableColumn implements Named
{
	private final String name;

	private final ColumnType type;

	public TableColumn(final String name, final ColumnType type)
	{
		this.name = name;
		this.type = type;
	}

	@Override
	public String name()
	{
		return name;
	}

	public ColumnType type()
	{
		return type;
	}

	/**
	 * Creates a new TableColumn with the same name and given type.
	 */
	public TableColumn type(final ColumnType type)
	{
		return new TableColumn(name, type);
	}

	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		result = prime * result + (name == null ? 0 : name.hashCode());
		result = prime * result + (type == null ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(final Object obj)
	{
		if (this == obj)
		{
			return true;
		}
		if (obj == null)
		{
			return false;
		}
		if (getClass() != obj.getClass())
		{
			return false;
		}
		final TableColumn other = (TableColumn) obj;
		if (name == null)
		{
			if (other.name != null)
			{
				return false;
			}
		}
		else if (!name.equals(other.name))
		{
			return false;
		}
		return true;
	}
}
